public class Demo12 {
    public static void main(String[] args) throws InterruptedException {
        //有三个线程，线程名称分别为：a，b，c。
        //每个线程打印自己的名称。
        //需要让他们同时启动，并按 c，b，a的顺序打印

        Object locker1 = new Object();
        Object locker2 = new Object();
        Object locker3 = new Object();

        Thread a = new Thread(() -> {
            synchronized(locker1) {
                try {
                    locker1.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.print("a ");
            synchronized(locker3) {
                locker3.notify();
            }
        });

        Thread b = new Thread(() -> {
            synchronized(locker2) {
                try {
                    locker2.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.print("b ");
            synchronized(locker1) {
                locker1.notify();
            }
        });

        Thread c = new Thread(() -> {
            synchronized(locker3) {
                try {
                    locker3.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.print("c ");
            synchronized(locker2) {
                locker2.notify();
            }
        });

        a.start();
        b.start();
        c.start();

        Thread.sleep(1000);

        synchronized(locker3) {
            locker3.notify();
        }
    }
}
